package nowcoder.hw.hj05;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * 提前知晓
 * a:97
 * A:65
 * 0:48
 */

/**
 * {@link java.io.BufferedReader}性能显著高于{@link Scanner}
 */
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main2 {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(System.in));
        String  input =null;
        while((input= bufferedReader.readLine()) != null){
            System.out.println(convert(input));
        }
    }

    private static Integer convert(String hex) {
        Integer sum = 0;
        for (int i = 2, pow = hex.length() - i - 1;
             i < hex.length();
             i++, pow = hex.length() - i - 1) {
            char c = hex.charAt(i);
            double num = 0;
            if (c >= '0' && c <= '9') num = (c - '0') * Math.pow(16, pow);
            else if (c >= 'A' && c <= 'F') num = (c - 'A' + 10) * Math.pow(16, pow);
            else num = (c - 'a' + 10) * Math.pow(16, pow);
            sum = Double.valueOf(num).intValue() + sum;
        }
        return sum;
    }

    private static Integer convert2(String hex) {
        int sum = 0;
        for (int i = 2, pow = hex.length() - i - 1;
             i < hex.length();
             i++, pow = hex.length() - i - 1) {
            int c = hex.charAt(i);
            double num = 0;
            if (c >= 'a') num = (c - 'a' + 10) * Math.pow(16, pow);
            else if (c >= 'A') num = (c - 'A' + 10) * Math.pow(16, pow);
            else num = (c-'0') * Math.pow(16, pow);
            sum = Double.valueOf(num).intValue() + sum;
        }
        return sum;
    }
}